package com.wrial.kind.design;
/*
 * @Author  Wrial
 * @Date Created in 11:24 2020/8/18
 * @Description  用两个队列实现一个栈
 */

import java.util.LinkedList;

public class Stack<E> {

    private LinkedList<E> queue1 = new LinkedList<>();//出栈
    private LinkedList<E> queue2 = new LinkedList<>();//辅助

    public void push(E num) {
        queue1.addFirst(num);
    }

    public E pop(){
        if (queue1==null) return null;
        if (queue1.size()==1) return queue1.removeLast();
        int size = queue1.size();
        for (int i = 0; i < size - 1; i++) {
            queue2.addFirst(queue1.removeLast());
        }
        return queue1.removeLast();
    }

    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(1);
        stack.push(2);
        System.out.println(stack.pop());
    }

}
